<?php
namespace wogu2\mvc\interceptor;

use wogu2\mvc\DispatcherInterface;

abstract class AbstractInterceptor implements InterceptorInterface
{
    protected $_dispatcher = null;
    protected $_runtime = null;
    protected $_request = null;
    
    public function init(DispatcherInterface $dispatcher) {
        $this->_dispatcher = $dispatcher;
        $this->_runtime = $dispatcher->getRuntime();
        $this->_request = $dispatcher->getRequest();
    }
    
    protected function addHeader($header) {
        $this->_runtime->headers[] = $header;
    }
    
    protected function appendBody($body) {
        $this->_runtime->body[] = $body;
    }
    
    protected function set($key, $value) {
        $this->_runtime->valueStack[$key] = $value;
    }
    
    protected function clear($key) {
        unset($this->_runtime->valueStack[$key]);
    }
    
    protected function get($key, $default = null) {
        return isset($this->_runtime->valueStack[$key]) ? $this->_runtime->valueStack[$key] : $default;
    }
}